//
//  LoginInputView.m
//  QMCXDriver
//
//  Created by Massimo on 2017/4/15.
//  Copyright © 2017年 Massimo. All rights reserved.
//

#import "LoginInputView.h"
#import "ReactiveCocoa.h"
@interface LoginInputView()<UITextFieldDelegate>
@property (nonatomic, weak) IBOutlet QTextFild *inputTextField;
@property (nonatomic, weak) IBOutlet UIButton *actionButton;
@property (nonatomic, copy) QInputTextChange textChangeBlock;
@property (nonatomic, copy) ActionCallBack actionBlock;
@end

@implementation LoginInputView
@synthesize isFocus = _isFocus;

- (void)setAction:(ActionCallBack)callBack{
    self.actionBlock = callBack;
}
- (void)awakeFromNib{
    [super awakeFromNib];
    _inputTextField.delegate = self; 
    __weak typeof(self) weakSelf = self;
    
    [[self.inputTextField rac_textSignal] subscribeNext:^(NSString* text){
        if (weakSelf.textChangeBlock) {
            weakSelf.textChangeBlock(text);
        }
    }];

}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    self.layer.borderColor = nil;
    self.layer.borderWidth = 0;
    if (_isFocus == YES) {
        self.layer.borderColor = LLColorRGB(141, 139, 150).CGColor;
        self.layer.borderWidth = 2.f/QScreenScale;
    }  
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    self.isFocus = YES;
    return YES;
} 
- (void)textFieldDidEndEditing:(UITextField *)textField{
    self.isFocus = NO;
}


- (IBAction)actionClick:(id)sender{
    if (self.actionBlock) {
        self.actionBlock(nil);
    }
}


#pragma mark - getter  setter


- (void)setIsFocus:(BOOL)isFocus{
    _isFocus = isFocus;
    [self setNeedsDisplay];
}
 
- (void)setTextChange:(QInputTextChange)callBack{
    self.textChangeBlock = callBack;
}
@end
